﻿#pragma once
//以下为引用控制台编码头文件
#include <io.h>
#include <fcntl.h>

//以下为引用应用程序的版本信息头文件
#include "resource.h"
//以下为引用DarkMoonUI头文件
#include "zyEnvironment.h"//黑月应用程序类
#include "zyWidget.h"//窗口类
#include "zyButton.h"//按钮类
#include "zyEditBox.h"//编辑框类
//#include "zyMenu.h"//菜单类
#include "zyLayoutBox.h"//布局类
#include "zyXMLRes.h"
#include "zyToolTips.h"
#include <zyD2DRenderer.h>

//以下为引用Skin皮肤头文件和库
#include "3rdparty\SkinH\SkinH.h"
#if defined(_WIN64)
#pragma comment(lib, "3rdparty\\SkinH\\x64\\SkinH_VC.lib")
#else
#pragma comment(lib, "3rdparty\\SkinH\\x86\\SkinHu.lib")
#endif

using namespace DarkMoonUI;//黑月的命名空间

class mainxml {
public:
	mainxml(const std::wstring& str1, zyWidget 主窗口) {
		m_cornerRadius = 10.0f;
		m_currentBlurRadius = 2.0f;
		m_currentShadowOffset = D2D1::Point2F(1.0f, 1.0f);
		m_currentOpacity = 0.12f;


		xml.Initialize();
		xml.LoadXml(str1);
		xml.创建窗口(NULL, L"main", 主窗口);
		m_hWnd= 主窗口.getHwnd();
		主窗口.事件_尺寸被改变(TRegEventCallBack(this, &mainxml::xml窗口事件_尺寸被改变));
		主窗口.事件_菜单被单击(TRegEventCallBack(this, &mainxml::xml窗口事件_菜单被单击));

		主窗口.取资源控件(L"状态栏1", sb);
		主窗口.取资源控件(L"超链接框1", lk);
		lk.事件_被单击(TRegEventCallBack(this, &mainxml::超链接框1_事件_被单击));

		主窗口.取资源控件(L"按钮2", bt2);
		bt2.事件_被单击(TRegEventCallBack(this, &mainxml::xml按钮事件_被点击));
		bt2.通用事件_重画(TRegEventCallBack(this, &mainxml::控件_通用事件_按钮重绘));
		//bt2.通用事件_窗口消息(TRegEventCallBack(this, &mainxml::控件_通用事件_回调过程));
		//主窗口.通用事件_窗口消息(TRegEventCallBack(this, &mainxml::控件_通用事件_回调过程));
		bt2.通用事件_鼠标位置被移动(TRegEventCallBack(this, &mainxml::控件_通用事件_按钮鼠标位置移动));
		bt2.通用事件_鼠标左键被按下(TRegEventCallBack(this, &mainxml::控件_通用事件_按钮鼠标左键按下));
		bt2.通用事件_鼠标左键被放开(TRegEventCallBack(this, &mainxml::控件_通用事件_按钮鼠标左键放开));
		bt2.通用事件_鼠标离开(TRegEventCallBack(this, &mainxml::控件_通用事件_按钮鼠标离开));
		zyComboBox combox;
		主窗口.取资源控件(L"组合框1", combox);
		combox.加入项目(L"选项1");
		combox.加入项目(L"选项2");
		zyToolTips tool;
		tool.创建();
		tool.添加(combox.getHwnd(), L"我是提示文本,你打我撒");

		zyButton bt1;
		主窗口.取资源控件(L"按钮4", bt1);
		bt1.事件_被单击(TRegEventCallBack(this, &mainxml::xml按钮事件_被点击));

		zyTreeView TreeView;
		主窗口.取资源控件(L"树型框1", TreeView);
		SetWindowTheme(TreeView.getHwnd(), L"explorer", 0);

		zyEditBox* edit = combox.取编辑框();
		edit->内容(L"我是组合框的编辑框");

		Gdiplus::Image* 通常图片 = new Gdiplus::Image(L"res\\正常.png");
		Gdiplus::Image* 点燃图片 = new Gdiplus::Image(L"res\\点燃.png");
		Gdiplus::Image* 按下图片 = new Gdiplus::Image(L"res\\按下.png");
		Gdiplus::Image* 图标 = new Gdiplus::Image(L"res\\图标.png");

		btex[0].创建(主窗口.getHwnd(), L"自绘超级按钮文本", POINT{ 10, 630 }, POINT{ 180, 30 }, 0);
		btex[0].通常颜色(Gdiplus::Color::MakeARGB(255, 66, 66, 66));
		btex[0].点燃颜色(Gdiplus::Color::MakeARGB(255, 64, 53, 130));
		btex[0].按下颜色(Gdiplus::Color::MakeARGB(255, 145, 131, 238));
		btex[0].文本色(Gdiplus::Color::MakeARGB(255, 250, 250, 250));

		btex[1].创建(主窗口.getHwnd(), L"自绘超级按钮文本", POINT{ 200, 630 }, POINT{ 180, 30 }, 0);
		btex[1].通常图片(通常图片);
		btex[1].点燃图片(点燃图片);
		btex[1].按下图片(按下图片);
		btex[1].图标(图标);
		btex[1].图标上偏移(-3);
		btex[1].图标左偏移(23);
		btex[1].置图片九宫();

		btex[2].创建(主窗口.getHwnd(), L"自绘超级按钮文本", POINT{ 390, 630 }, POINT{ 180, 30 }, 0);
		btex[2].通常颜色(Gdiplus::Color::MakeARGB(255, 66, 66, 66));
		btex[2].点燃颜色(Gdiplus::Color::MakeARGB(255, 64, 53, 130));
		btex[2].按下颜色(Gdiplus::Color::MakeARGB(255, 145, 131, 238));
		btex[2].文本色(Gdiplus::Color::MakeARGB(255, 250, 250, 250));
		btex[2].圆角度(10);
	}

	~mainxml() {
		// 释放资源
	}

	int 超链接框1_事件_被单击(HWND hWnd, int 链接索引, const std::wstring& URL, const std::wstring& ID) {
		std::wcout << L"main_超链接框1_事件_被单击: " << URL << L" 链接索引: " << 链接索引 << std::endl;
		return 0;
	}
	LRESULT 控件_通用事件_按钮鼠标离开(HWND hWnd) {
		if (g_IsMouseOverButton) {
			g_IsMouseOverButton = false;
			g_ButtonState = STATE_NORMAL;
			InvalidateRect(hWnd, NULL, FALSE); // 触发重绘
		}
		return 0;
	}
	LRESULT 控件_通用事件_按钮鼠标左键放开(HWND hWnd, WORD x, WORD y, int 功能键状态) {
		if (!bt2.getHwnd()) return 0;
		POINT pt = { x, y };
		RECT buttonRect;
		GetWindowRect(bt2.getHwnd(), &buttonRect);
		ScreenToClient(hWnd, (LPPOINT)&buttonRect);
		ScreenToClient(hWnd, (LPPOINT)&buttonRect + 1);

		if (PtInRect(&buttonRect, pt)) {
			g_ButtonState = STATE_HOVERED;
			InvalidateRect(bt2.getHwnd(), NULL, FALSE); // 触发重绘
		}
		return 0;
	}
	LRESULT 控件_通用事件_按钮鼠标左键按下(HWND hWnd, WORD x, WORD y, int 功能键状态) {
		if (!bt2.getHwnd()) return 0;
		POINT pt = { x, y };
		RECT buttonRect;
		GetWindowRect(bt2.getHwnd(), &buttonRect);
		ScreenToClient(hWnd, (LPPOINT)&buttonRect);
		ScreenToClient(hWnd, (LPPOINT)&buttonRect + 1);

		if (PtInRect(&buttonRect, pt)) {
			g_ButtonState = STATE_PRESSED;
			InvalidateRect(bt2.getHwnd(), NULL, FALSE); // 触发重绘
		}
		return 0;
	}
	LRESULT 控件_通用事件_按钮鼠标位置移动(HWND hWnd, WORD x, WORD y, int 功能键状态) {
		POINT pt = { x,y };
		RECT buttonRect;
		GetWindowRect(hWnd, &buttonRect);
		ScreenToClient(hWnd, (LPPOINT)&buttonRect);
		ScreenToClient(hWnd, (LPPOINT)&buttonRect + 1);

		if (PtInRect(&buttonRect, pt)) {
			if (!g_IsMouseOverButton) {
				g_IsMouseOverButton = true;
				g_ButtonState = STATE_HOVERED;
				InvalidateRect(hWnd, NULL, FALSE); // 触发重绘
			}
		}
		else {
			if (g_IsMouseOverButton) {
				g_IsMouseOverButton = false;
				g_ButtonState = STATE_NORMAL;
				InvalidateRect(hWnd, NULL, FALSE); // 触发重绘
			}
		}
		return 0;
	}
	LRESULT 控件_通用事件_按钮重绘(HWND hWnd, HDC hdc, int left, int top, int right, int bottom) {
		zyD2DRenderer* pRenderer = new zyD2DRenderer(hWnd, right-left, bottom-top);
		pRenderer->BeginDraw();
		pRenderer->Clear(D2D1::ColorF(D2D1::ColorF::White));

		D2D1_RECT_F rect = D2D1::RectF(left, top, right, bottom);

		// 动态更新阴影效果
		float targetBlurRadius = 0.0f;
		float	targetOpacity = 0.0f;
		D2D1_POINT_2F targetShadowOffset = { 0 };

		switch (g_ButtonState) {
		case STATE_NORMAL:
			targetBlurRadius = 2.0f;
			targetShadowOffset = D2D1::Point2F(1.0f, 1.0f);
			targetOpacity = 0.12f;
			break;
		case STATE_HOVERED:
			targetBlurRadius = 3.0f;
			targetShadowOffset = D2D1::Point2F(2.0f, 2.0f);
			targetOpacity = 0.15f;
			break;
		case STATE_PRESSED:
			targetBlurRadius = 1.0f;
			targetShadowOffset = D2D1::Point2F(1.2f, 1.2f);
			targetOpacity = 0.1f;
			break;
		}


		// 平滑过渡
		m_currentBlurRadius = lerp(m_currentBlurRadius, targetBlurRadius, 0.1f);
		m_currentShadowOffset.x = lerp(m_currentShadowOffset.x, targetShadowOffset.x, 0.1f);
		m_currentShadowOffset.y = lerp(m_currentShadowOffset.y, targetShadowOffset.y, 0.1f);
		m_currentOpacity = lerp(m_currentOpacity, targetOpacity, 0.1f);

		// 绘制阴影
		pRenderer->DrawShadow(rect, m_cornerRadius, m_currentBlurRadius, D2D1::ColorF(D2D1::ColorF::Black), m_currentShadowOffset, m_currentOpacity);

		// 绘制按钮背景
		D2D1_COLOR_F bgColor;
		switch (g_ButtonState) {
		case STATE_NORMAL:
			bgColor = D2D1::ColorF(D2D1::ColorF::LightBlue);
			break;
		case STATE_HOVERED:
			bgColor = D2D1::ColorF(D2D1::ColorF::LightGreen);
			break;
		case STATE_PRESSED:
			bgColor = D2D1::ColorF(D2D1::ColorF::LightCoral);
			break;
		}
		rect = D2D1::RectF(left + 2, top + 2, right - 2, bottom - 2);
		pRenderer->FillRoundedRectangle(rect, m_cornerRadius, m_cornerRadius, bgColor);

		// 获取系统默认字体和大小
		NONCLIENTMETRICS ncm = { sizeof(NONCLIENTMETRICS) };
		SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0);

		LOGFONT lf = ncm.lfMessageFont;
		float fontSize = static_cast<float>(-lf.lfHeight); // 获取默认字体大小
		// 绘制按钮文本
		IDWriteTextFormat* pTextFormat = pRenderer->CreateTextFormat(lf.lfFaceName, fontSize, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL);
		pTextFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER);
		pTextFormat->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_CENTER);
		pRenderer->DrawText(bt2.取文本().c_str(), rect, pTextFormat, D2D1::ColorF(D2D1::ColorF::Black));
		pTextFormat->Release();

		pRenderer->EndDraw();
		delete pRenderer;
		
		return 0;
	}
	
	LRESULT 通用事件_回调过程(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL* bHandled) {
		switch (uMsg) {
		case WM_DRAWITEM: {
			LPDRAWITEMSTRUCT pDrawItem = (LPDRAWITEMSTRUCT)lParam;
			if (pDrawItem->CtlID == 101) { // 按钮的ID
				zyD2DRenderer* pRenderer = new zyD2DRenderer(bt2.getHwnd(), bt2.宽度(), bt2.高度());
				pRenderer->BeginDraw();
				pRenderer->Clear(D2D1::ColorF(D2D1::ColorF::White));

				D2D1_RECT_F rect = D2D1::RectF(pDrawItem->rcItem.left, pDrawItem->rcItem.top, pDrawItem->rcItem.right, pDrawItem->rcItem.bottom);

				// 动态更新阴影效果
				float targetBlurRadius = 0.0f;
				float	targetOpacity =0.0f;
				D2D1_POINT_2F targetShadowOffset = {0};

				switch (g_ButtonState) {
				case STATE_NORMAL:
					targetBlurRadius = 2.0f;
					targetShadowOffset = D2D1::Point2F(1.0f, 1.0f);
					targetOpacity = 0.12f;
					break;
				case STATE_HOVERED:
					targetBlurRadius = 3.0f;
					targetShadowOffset = D2D1::Point2F(2.0f, 2.0f);
					targetOpacity = 0.15f;
					break;
				case STATE_PRESSED:
					targetBlurRadius = 1.0f;
					targetShadowOffset = D2D1::Point2F(1.2f, 1.2f);
					targetOpacity = 0.1f;
					break;
				}


				// 平滑过渡
				m_currentBlurRadius = lerp(m_currentBlurRadius, targetBlurRadius, 0.1f);
				m_currentShadowOffset.x = lerp(m_currentShadowOffset.x, targetShadowOffset.x, 0.1f);
				m_currentShadowOffset.y = lerp(m_currentShadowOffset.y, targetShadowOffset.y, 0.1f);
				m_currentOpacity = lerp(m_currentOpacity, targetOpacity, 0.1f);

				// 绘制阴影
				pRenderer->DrawShadow(rect, m_cornerRadius, m_currentBlurRadius, D2D1::ColorF(D2D1::ColorF::Black), m_currentShadowOffset, m_currentOpacity);

				// 绘制按钮背景
				D2D1_COLOR_F bgColor;
				switch (g_ButtonState) {
				case STATE_NORMAL:
					bgColor = D2D1::ColorF(D2D1::ColorF::LightBlue);
					break;
				case STATE_HOVERED:
					bgColor = D2D1::ColorF(D2D1::ColorF::LightGreen);
					break;
				case STATE_PRESSED:
					bgColor = D2D1::ColorF(D2D1::ColorF::LightCoral);
					break;
				}
				rect = D2D1::RectF(pDrawItem->rcItem.left + 2, pDrawItem->rcItem.top + 2, pDrawItem->rcItem.right - 2, pDrawItem->rcItem.bottom - 2);
				pRenderer->FillRoundedRectangle(rect, m_cornerRadius, m_cornerRadius, bgColor);

				// 获取系统默认字体和大小
				NONCLIENTMETRICS ncm = { sizeof(NONCLIENTMETRICS) };
				SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0);

				LOGFONT lf = ncm.lfMessageFont;
				float fontSize = static_cast<float>(-lf.lfHeight); // 获取默认字体大小
				// 绘制按钮文本
				IDWriteTextFormat* pTextFormat = pRenderer->CreateTextFormat(lf.lfFaceName, fontSize, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL);
				pTextFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER);
				pTextFormat->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_CENTER);
				pRenderer->DrawText(bt2.取文本().c_str(), rect, pTextFormat, D2D1::ColorF(D2D1::ColorF::Black));
				pTextFormat->Release();

				pRenderer->EndDraw();
				delete pRenderer;
			}
			break;
		}
		case WM_MOUSEMOVE: {
			if (!bt2.getHwnd()) return 0;
			POINT pt = { LOWORD(lParam), HIWORD(lParam) };
			RECT buttonRect;
			GetWindowRect(bt2.getHwnd(), &buttonRect);
			ScreenToClient(hWnd, (LPPOINT)&buttonRect);
			ScreenToClient(hWnd, (LPPOINT)&buttonRect + 1);

			if (PtInRect(&buttonRect, pt)) {
				if (!g_IsMouseOverButton) {
					g_IsMouseOverButton = true;
					g_ButtonState = STATE_HOVERED;
					InvalidateRect(bt2.getHwnd(), NULL, FALSE); // 触发重绘
				}
			}
			else {
				if (g_IsMouseOverButton) {
					g_IsMouseOverButton = false;
					g_ButtonState = STATE_NORMAL;
					InvalidateRect(bt2.getHwnd(), NULL, FALSE); // 触发重绘
				}
			}
			break;
		}
		case WM_LBUTTONDOWN: {
			if (!bt2.getHwnd()) return 0;
			POINT pt = { LOWORD(lParam), HIWORD(lParam) };
			RECT buttonRect;
			GetWindowRect(bt2.getHwnd(), &buttonRect);
			ScreenToClient(hWnd, (LPPOINT)&buttonRect);
			ScreenToClient(hWnd, (LPPOINT)&buttonRect + 1);

			if (PtInRect(&buttonRect, pt)) {
				g_ButtonState = STATE_PRESSED;
				InvalidateRect(bt2.getHwnd(), NULL, FALSE); // 触发重绘
			}
			break;
		}
		case WM_LBUTTONUP: {
			if (!bt2.getHwnd()) return 0;
			POINT pt = { LOWORD(lParam), HIWORD(lParam) };
			RECT buttonRect;
			GetWindowRect(bt2.getHwnd(), &buttonRect);
			ScreenToClient(hWnd, (LPPOINT)&buttonRect);
			ScreenToClient(hWnd, (LPPOINT)&buttonRect + 1);

			if (PtInRect(&buttonRect, pt)) {
				g_ButtonState = STATE_HOVERED;
				InvalidateRect(bt2.getHwnd(), NULL, FALSE); // 触发重绘
			}
			break;
		}
		case WM_ERASEBKGND:
			return 1; // 禁止背景擦除
		
		}
		return 0;
	}

	int xml按钮事件_被点击(HWND hWnd, int ID) {
		if (ID <= 108 && ID >= 101)
			std::wcout << L"main_按钮被点击: " << ID << std::endl;
		return 0;
	}

	int xml窗口事件_菜单被单击(zyForm* 来源对象, int ID) {
		if (ID == 10000) {
			std::wcout << L"打开" << std::endl;
		}
		else if (ID == 10001) {
			std::wcout << L"保存ID:" << ID << std::endl;
		}
		else if (ID == 10002) {
			std::wcout << L"退出" << std::endl;
		}
		else if (ID == 10003) {
			std::wcout << L"触发快捷键事件" << std::endl;
		}
		return 0;
	}

	int xml窗口事件_尺寸被改变(HWND hWnd, WORD x, WORD y) {
		sb.自动大小();
		return 0;
	}

	// 按钮状态枚举
	enum ButtonState {
		STATE_NORMAL,
		STATE_HOVERED,
		STATE_PRESSED
	};
	zyXMLRes xml;
private:
	// 线性插值函数
	float lerp(float a, float b, float t) {
		return a + t * (b - a);
	}

	
	zyButton bt2;
	zyButtonEx btex[5];
	zyLinkBox lk;
	zyStatusBar sb;
	HWND m_hWnd;
	// 按钮状态
	ButtonState g_ButtonState = STATE_NORMAL;
	bool g_IsMouseOverButton = false;

	// 阴影效果参数
	float m_cornerRadius = 10.0f;
	float m_currentBlurRadius = 2.0f;
	D2D1_POINT_2F m_currentShadowOffset = D2D1::Point2F(1.0f, 1.0f);
	float m_currentOpacity = 0.2f;
};


//以下为类方式调用黑月界面
class MainWidget : public zyWidget {
public:
	MainWidget() {
		边框(窗口边框_普通可调边框);
		事件_创建完毕(TRegEventCallBack(this, &MainWidget::on_主窗口_create));
		事件_菜单被单击(TRegEventCallBack(this, &MainWidget::on_主窗口_菜单被单击));
		事件_系统命令(TRegEventCallBack(this, &MainWidget::on_主窗口_系统命令));
		创建(NULL, L"C++我是主窗口,黑月界面模块演示-By:易团雪", POINT{ -1,-1 }, POINT{ 980, 500 }, WS_MINIMIZEBOX);
		Esc关闭(true);
		随意移动(true);


		菜单1.绑定系统菜单(取窗口句柄());
		菜单1.添加项目(L"新增的系统菜单", 10003);

		创建菜单();
		std::wstring s[11] = {
			L"拉伸对齐",
			L"水平左下对齐",
			L"水平下中对齐",
			L"水平右下对齐",
			L"水平左中对齐",
			L"垂直居中对齐",
			L"垂直右中对齐",
			L"垂直左上对齐",
			L"垂直上中对齐",
			L"垂直右上对齐",
			L"无对齐",
		};

		for (int i = 0; i < 11; i++) {
			//std::wstring src = L"按钮" + std::to_wstring(i + 1);
			bt2[i].创建(取窗口句柄(), s[i], POINT{(5 + 76) * i +5 , 10}, POINT{76, 30},i);
			bt2[i].事件_被单击(TRegEventCallBack(this, &MainWidget::on_按钮事件_被点击));
			RECT rc = { 5,5,5,5 };
			线性布局.插入项目(i, bt2[i], 线性布局对齐_右中,&rc);
		}


		std::wstring src = L"我是编辑框文本。多行的文本，黑月界面模块。Windows平台轻量级Win32-API界面框架，和易语言一样的调用方式。比MFC小巧，轻盈，简单，易用，方便。提供Win32风格的API,支持生成lib和dll。生成的dll可以被其他语言调用。";
		edit.创建(*this, src, POINT{ 10,50 }, POINT{ 260,100 }, 0, ES_MULTILINE | ES_AUTOVSCROLL | WS_VSCROLL);

		编辑框1.垂直居中(true);
		编辑框1.创建(*this, L"垂直居中新方法实现，增加超级进度条，分组框增加系统主题", POINT{ 10, 160 }, POINT{ 260, 50 }, ES_AUTOHSCROLL | WS_HSCROLL);
		
		//编辑框1.背景色(RGB(255,0,0));
		const wchar_t* PASSWORD_MASK = L"*";
		编辑框1.置密码遮盖符(PASSWORD_MASK);
		//线性布局.模式(线性布局模式_水平);
		//线性布局.添加项目(edit);
		//线性布局.添加项目(编辑框1);
		//线性布局.添加项目(bt2[0]);
		//线性布局.添加项目(bt2[1]);
		//线性布局.添加项目(bt2[2]);
		//线性布局.添加项目(bt2[3]);

		置布局(线性布局);

	}

public: // Events
	int on_主窗口_create(zyForm* 来源对象) {
		std::wcout << L"main_窗口创建完成: " << (int)(INT_PTR)来源对象->getHwnd() << std::endl;

		return 0;
	}

	int on_主窗口_系统命令(HWND hWnd, int ID, WORD x, WORD y) {
		if (ID == 10003) {
			std::wcout << L"新增的系统菜单" << std::endl;
		}
		else
		{
			std::wcout << L"main_系统命令ID：" << ID << L" 横坐标：" << x << L" 纵坐标：" << y << std::endl;
		}

		return 0;
	}

	int on_按钮事件_被点击(HWND hWnd, int id) {

		switch (id){
            case 0:
				线性布局.置项目对齐(1, 线性布局对齐_拉伸);
                break;
            case 1:
				线性布局.置项目对齐(1, 线性布局对齐_左下);
                break;
			case 2:
				线性布局.置项目对齐(1, 线性布局对齐_下中);
				break;
			case 3:
				线性布局.置项目对齐(1, 线性布局对齐_右下);
				break;
			case 4:
				线性布局.置项目对齐(1, 线性布局对齐_左中);
				break;
			case 5:
				线性布局.置项目对齐(1, 线性布局对齐_居中);
				break;
			case 6:
				线性布局.置项目对齐(1, 线性布局对齐_右中);
				break;
			case 7:
				线性布局.置项目对齐(1, 线性布局对齐_左上);
				break;
			case 8:
				线性布局.置项目对齐(1, 线性布局对齐_上中);
				break;
			case 9:
				线性布局.置项目对齐(1, 线性布局对齐_右上);
				break;
			default:
				线性布局.置项目对齐(1, 线性布局对齐_无对齐);
                break;
        }
		置布局(线性布局);



		return 0;
	}

	int on_主窗口_菜单被单击(zyForm* 来源对象, int ID) {

		if (ID == 10000) {
			std::wcout << L"打开" << std::endl;
			菜单_文件.选中项目(ID, !菜单_文件.是否选中(ID));
		}
		else if (ID == 10001) {
			std::wstring wstr = L"测试字符串";
			std::wcout << L"保存ID:" << ID << L" 标题:" << 菜单_文件.取项目标题(ID) << std::endl;
			菜单_文件.选中项目(ID, !菜单_文件.是否选中(ID));
		}
		else if (ID == 10002) {
			std::wcout << L"退出" << std::endl;
			来源对象->销毁();
		}

		return 0;
	}
protected:
	bool 被创建(zyForm* 来源对象) override final
	{
		std::wcout << L"override main_窗口创建完成: " << (int)(INT_PTR)来源对象->getHwnd() << std::endl;

		return zyWidget::被创建(来源对象); // 调用基类的被创建 
	}

private:
	int 创建菜单() {

		菜单_文件.销毁();
		菜单_文件.创建弹出菜单();
		菜单_文件.添加项目(L"打开(&O)\tCtrl + O", 10000);
		菜单_文件.添加项目(L"保存(&S)\tCtrl + S", 10001);
		菜单_文件.添加分割线();
		菜单_文件.添加项目(L"退出(&X)", 10002);

		菜单_单选.销毁();
		菜单_单选.创建弹出菜单();
		菜单_单选.添加项目(L"男", 10003);
		菜单_单选.添加项目(L"女", 10004);
		菜单_单选.添加项目(L"未知", 10005);
		菜单_单选.添加分割线();
		菜单_单选.添加项目(L"第二组1", 10006);
		菜单_单选.添加项目(L"第二组2", 10007);
		菜单_单选.添加项目(L"第二组3", 10008);
		菜单_单选.单选菜单(0, 0, 2);  // 默认先选中第一个
		菜单_单选.单选菜单(4, 4, 6);  // 默认先选中第二组第一个
		菜单_单选.置菜单背景色(255);


		// 最后添加到菜单栏
		菜单栏.销毁();
		菜单栏.创建菜单栏();
		菜单栏.添加弹出菜单(菜单_文件, L"文件(&F)");
		菜单栏.添加弹出菜单(菜单_单选, L"单选(&R)");
		置菜单(菜单栏);
		return 0;
	}

private:
	zyButton bt2[11];
	zyEditBox edit;
	zyEditBox 编辑框1;
	zyMenu 菜单_文件;
	zyMenu 菜单1;
	zyMenu 菜单_单选;
	zyMenu 菜单栏;
	zyLayoutBox 线性布局;
};

//以下为c方式调用黑月界面
zyMenu 菜单_文件;
zyLayout 编辑框1布局;

int 窗口事件_系统命令(HWND hWnd, int ID, WORD x, WORD y) {
	if (ID == 10003) {
			std::wcout << L"新增的系统菜单" << std::endl;
	}
	else
	{
		std::wcout << L"main_系统命令ID：" << ID << L" 横坐标：" << x << L" 纵坐标：" << y << std::endl;
	}
	
	return 0;
}
int 按钮事件_被点击(HWND hWnd, int ID) {

	if (ID <= 108 && ID >= 101)
		std::wcout << L"main_按钮被点击: " << ID << std::endl;
	return 0;
}
int 窗口事件_菜单被单击(zyForm* 来源对象, int ID) {

	if (ID == 10000) {
		std::wcout << L"打开" << std::endl;
		菜单_文件.选中项目(ID, !菜单_文件.是否选中(ID));
	}
	else if (ID == 10001) {
		std::wstring wstr = L"测试字符串";
		std::wcout << L"保存ID:" << ID << L" 标题:" << 菜单_文件.取项目标题(ID) << std::endl;
		菜单_文件.选中项目(ID, !菜单_文件.是否选中(ID));
	}
	else if (ID == 10002) {
		std::wcout << L"退出" << std::endl;
		来源对象->销毁();
	}
	else if (ID == 10003) {
		std::wcout << L"触发快捷键事件" << std::endl;

	}

	return 0;
}
int 创建菜单(zyForm* 来源对象) {

	菜单_文件.销毁();
	菜单_文件.创建弹出菜单();
	菜单_文件.添加项目(L"打开(&O)\tCtrl + O", 10000);
	菜单_文件.添加项目(L"保存(&S)\tCtrl + S", 10001);
	菜单_文件.添加分割线();
	菜单_文件.添加项目(L"退出(&X)", 10002);
	zyMenu 菜单_单选;
	菜单_单选.销毁();
	菜单_单选.创建弹出菜单();
	菜单_单选.添加项目(L"男", 10003);
	菜单_单选.添加项目(L"女", 10004);
	菜单_单选.添加项目(L"未知", 10005);
	菜单_单选.添加分割线();
	菜单_单选.添加项目(L"第二组1", 10006);
	菜单_单选.添加项目(L"第二组2", 10007);
	菜单_单选.添加项目(L"第二组3", 10008);
	菜单_单选.单选菜单(0, 0, 2);  // 默认先选中第一个
	菜单_单选.单选菜单(4, 4, 6);  // 默认先选中第二组第一个
	菜单_单选.置菜单背景色(255);

	zyMenu 菜单栏;
	// 最后添加到菜单栏
	菜单栏.销毁();
	菜单栏.创建菜单栏();
	菜单栏.添加弹出菜单(菜单_文件, L"文件(&F)");
	菜单栏.添加弹出菜单(菜单_单选, L"单选(&R)");
	来源对象->置菜单(菜单栏);
	return 0;
}
int 窗口事件_创建完成(zyForm* 来源对象) {
	std::wcout << L"main_窗口创建完成: " << (int)(INT_PTR)来源对象->getHwnd() << std::endl;
	zyMenu 菜单1;
	菜单1.绑定系统菜单(来源对象->取窗口句柄());
	菜单1.添加项目(L"新增的系统菜单", 10003);

	创建菜单(来源对象);

	static zyButton bt2[8];
	for (int i = 0; i < 8; i++) {
		std::wstring src = L"按钮" + std::to_wstring(i + 1);
		bt2[i].创建(来源对象->取窗口句柄(), src, POINT{ (10 + 60) * i + 10 , 10 }, POINT{ 60, 30 }, 101 + i);
		bt2[i].事件_被单击(TRegEventCallBack(按钮事件_被点击));

	}

	static zyEditBox edit;
	std::wstring src = L"我是编辑框文本。多行的文本，黑月界面模块。Windows平台轻量级Win32-API界面框架，和易语言一样的调用方式。比MFC小巧，轻盈，简单，易用，方便。提供Win32风格的API,支持生成lib和dll。生成的dll可以被其他语言调用。";
	edit.创建(*来源对象, src, POINT{ 10,50 }, POINT{ 260,100 }, 0, ES_MULTILINE | ES_AUTOVSCROLL | WS_VSCROLL);

	static zyEditBox 编辑框1;

	编辑框1.创建(来源对象->取窗口句柄(), L"垂直居中新方法实现，增加超级进度条，分组框增加系统主题", POINT{ 10, 160 }, POINT{ 260, 50 }, ES_AUTOHSCROLL | WS_HSCROLL);
	编辑框1.垂直居中(true);
	//编辑框1.背景色(RGB(255,0,0));
	const wchar_t* PASSWORD_MASK = L"*";
	编辑框1.置密码遮盖符(PASSWORD_MASK);
	
	编辑框1布局.添加项目(编辑框1);	

	来源对象->置布局(编辑框1布局);

	return 0;
}


//设置控制台编码,与界面无关
static void setStdCodePage()
{
	std::ignore = _setmode(_fileno(stdout), _O_WTEXT);
	std::ignore = _setmode(_fileno(stderr), _O_WTEXT);
	std::ignore = _setmode(_fileno(stdin), _O_WTEXT);
}

//入口函数
//int APIENTRY wWinMain(_In_ HINSTANCE hInstance,_In_opt_ HINSTANCE hPrevInstance,_In_ LPWSTR lpCmdLine,_In_ int nCmdShow){
int main(int argc, char* argv[]) {
	setStdCodePage();
	setCurrentDirectoryToProcessDirectory();
	//界面初始化操作
	zyApplications app;
	app.初始化();

	/*zyWidget 主窗口;
	主窗口.事件_菜单被单击(TRegEventCallBack(窗口事件_菜单被单击));
	主窗口.边框(窗口边框_普通可调边框);
	主窗口.事件_创建完毕(TRegEventCallBack(窗口事件_创建完成));
	主窗口.事件_系统命令(TRegEventCallBack(窗口事件_系统命令));
	主窗口.创建(NULL, L"C++我是主窗口,黑月界面模块演示-By:易团雪", POINT{ -1,-1 }, POINT{ 600, 500 }, WS_MINIMIZEBOX);
	主窗口.Esc关闭(true);
	主窗口.随意移动(true);*/

	//MainWidget 主窗口;
	
	//HWND hWnd = 主窗口.取窗口句柄();

	//zyIcon 主窗口图标;
	//主窗口图标.载入图标(IDI_ICON1);
	//主窗口.置图标(主窗口图标, 1);

	std::wstring str1 = app.GetDirectory() + L"\\res\\main.xml";
	zyWidget 主窗口;
	mainxml xml窗口(str1,主窗口);

	//载入快捷键只能在main函数中设置。否则无效
	zyAccelTable accel;	
	xml窗口.xml.载入快捷键(L"accMain", accel);
	主窗口.置快捷键(accel);
		
	zyPropertyGrid 属性框1;
	属性框1.创建(主窗口,L"", POINT{10, 350 }, POINT{252, 275}, 0, ES_AUTOHSCROLL | WS_HSCROLL);
	PropertyGrid_item *group = 属性框1.插入项目_分组(0, L"分组一");
	属性框1.插入项目_文本(0, group, L"名称", L"编辑框1");
	属性框1.插入项目_文本(0, group, L"矩形", L"11,120,20,132");
	group = 属性框1.插入项目_分组(0, L"分组二");
	属性框1.插入项目_文本(0, group, L"尺寸", L"320,252");
	属性框1.插入项目_长文本(0, group, L"长文本", L"我是长文本");
	group = 属性框1.插入项目_列表(0, group, L"边框");
	属性框1.列表_添加项目(group, L"列表1_无边框",0);
	属性框1.列表_添加项目(group, L"列表2_单线框", 1);
	属性框1.列表_添加项目(group, L"列表3_凸框", 2);

	//std::wstring gg = base64_encode(ReadFileToBinary(L"E:\\C++\\ExDUIR\\msvc\\demo\\res\\editbkg.jpg"));
	//std::wcout << gg << std::endl;

	//combox.置现行选中项(0);
	//以下为设置皮肤
	//std::wstring str = app.GetDirectory() + L"\\蓝色电脑管家.she";
	//SkinH_AttachEx(str.c_str(), 0);
	//SkinH_SetFontEx(hWnd, L"微软雅黑", 17, 6, 1, 0, 0, 0);
	//SkinH_SetTitleMenuBar(hWnd, 1,0,0,10);


	app.运行(主窗口);

	return 0;
}
